home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / stdio / c / fgets < prev    next >
Text File  |  1996-11-09  |  940b  |  40 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/fgets,v $
  4.  * $Date: 1996/11/06 22:01:42 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: fgets,v $
  10.  * Revision 1.2  1996/11/06 22:01:42  unixlib
  11.  * Yet more changes by NB, PB and SC.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:32:42  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: fgets,v 1.2 1996/11/06 22:01:42 unixlib Rel $";
  19.  
  20. #include <stdio.h>
  21.  
  22. __STDIOLIB__
  23.  
  24. char *
  25. fgets (char *_s, size_t n, FILE *f)
  26. {
  27.   register char *s = _s;
  28.   register int c = 0;
  29.  
  30.   /* Repeat, obtaining characters until we hit a newline,
  31.      or exceed our count, n.  */
  32.   while (--n > 0 && (c = getc (f)) >= 0)
  33.     if ((*s++ = c) == '\n')
  34.       break;
  35.  
  36.   *s = 0;
  37.  
  38.   return ((c < 0 && s == _s) ? 0 : _s);
  39. }
  40.